package per.wsj.workmanager

import android.content.Context
import android.os.Looper
import android.os.SystemClock
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters
import per.wsj.commonlib.utils.LogUtil

class MainWorker(ctx: Context, params: WorkerParameters) : Worker(ctx, params) {
    override fun doWork(): Result {
        val param = inputData.getInt("times",0)
        LogUtil.LOGE("这里需要执行{$param}次")
        if(Looper.myLooper()==Looper.getMainLooper()){
            LogUtil.LOGE("当前线程：主线程"+Thread.currentThread().name)
        }else{
            LogUtil.LOGE("当前线程：子线程 "+Thread.currentThread().name)
        }
        for (i in 0..param){
            SystemClock.sleep(1000)
            LogUtil.LOGE("i:$i")
        }

        val outputData = Data.Builder()
            .putString("result","执行完成")
            .build()

        return Result.success(outputData)
    }
}